using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TrainingsApp.Model;
using TrainingsApp.Helper;
using WisDragon.Framework.Data.DataAccess;

namespace TrainingsApp.DAL
{
    public class TS_Class_DAL
    {
        public static TS_Class_Collecion TS_Class_ListByPaging(int pageSize, int pageIndex)
        {
            TS_Class_Collecion list = new TS_Class_Collecion();
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Class_ListByPaging");
                cmd.SetParameterValue("@pageSize", pageSize);
                cmd.SetParameterValue("@pageIndex", pageIndex);
                List<TS_Class_Entity> pageList = cmd.ExecuteEntityList<TS_Class_Entity>();
                list.TS_Class_List = pageList;
                list.TotalCount = Convert.ToInt32(cmd.GetParameterValue("@recordCount"));
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

            return list;

        }

        public static List<TS_Grade_Entity> TS_Class_ListGrade(int schoolId)
        {
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Class_ListGrade");
                cmd.SetParameterValue("@SchoolId", schoolId);

                return cmd.ExecuteEntityList<TS_Grade_Entity>();

            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

            return new List<TS_Grade_Entity>(0);
        }

        public static List<TS_Class_Entity> TS_Class_ListClass(int schoolId, int grade)
        {


            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Class_ListClass");
                cmd.SetParameterValue("@SchoolId", schoolId);
                cmd.SetParameterValue("@Grade", grade);

                return cmd.ExecuteEntityList<TS_Class_Entity>();

            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

            return new List<TS_Class_Entity>(0);
        }

        public static List<TS_Class_Entity> TS_Class_ListBySchoolId(int schoolId)
        {
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Class_ListBySchoolId");
                cmd.SetParameterValue("@SchoolId", schoolId);

                return cmd.ExecuteEntityList<TS_Class_Entity>();

            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

            return new List<TS_Class_Entity>(0);

        }

        public static TS_Class_Entity TS_Class_View(System.Int64 Idx)
        {
            TS_Class_Entity c = default(TS_Class_Entity);
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Class_View");
                cmd.SetParameterValue("@Idx", Idx);
                c = cmd.ExecuteEntity<TS_Class_Entity>();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }

        public static TS_Class_Entity TS_Class_Add(TS_Class_Entity entity)
        {
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Class_Add");
                //     cmd.SetParameterValue("@Idx", entity.Idx);
                cmd.SetParameterValue("@Grade", entity.Grade);
                cmd.SetParameterValue("@ClassName", entity.ClassName);
                cmd.SetParameterValue("@SchoolId", entity.SchoolId);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

            return entity;
        }

        public static void TS_Class_Update(TS_Class_Entity entity)
        {
            bool succ = false;
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Class_Update");
                cmd.SetParameterValue("@Idx", entity.Idx);
                cmd.SetParameterValue("@Grade", entity.Grade);
                cmd.SetParameterValue("@ClassName", entity.ClassName);
                cmd.ExecuteNonQuery();
                succ = true;
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

        }

        public static void TS_Class_Delete(System.Int64 Idx)
        {
            bool succ = false;
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Class_Delete");
                cmd.SetParameterValue("@Idx", Idx);
                cmd.ExecuteNonQuery();
                succ = true;
            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

        }

        public static List<TS_Class_Entity> TS_Class_GetClassesByUserId(long userId)
        {
            try
            {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_Class_GetClassesByUserId");
                cmd.SetParameterValue("@userId", userId);

                return cmd.ExecuteEntityList<TS_Class_Entity>();

            }
            catch (Exception ex)
            {
                ExceptionHelper.ProcessException(ex);
            }

            return new List<TS_Class_Entity>(0);

        }
    }
}
